//
//  XJOrderDetailHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/28.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  订单详情头部view

#import "XJOrderDetailHeaderView.h"
@interface XJOrderDetailHeaderView()
@property(nonatomic, strong) UIView *bgView;


@property(nonatomic, strong) UIView *aboveBgView; // 上半部(icon+ 等待买家付款+2天23消失自动取消订单)
@property(nonatomic, strong) UIImageView *statusIconIv; // 状态icon
@property(nonatomic, strong) UILabel *matterLabe;// 等待买家付款.等待买家收货
@property(nonatomic, strong) UILabel *expireLabel;//到期时间label 这个控件有时有时没有。



@property(nonatomic, strong) UIView *belowBgView;//下半部(icon+张小花+1588888888+ 浙江省滨江区华盛达)
@property(nonatomic, strong) UIImageView *locationIcon; //定位图标
@property(nonatomic, strong) UILabel *nameLabel; //姓名:张小花
@property(nonatomic, strong) UILabel *phoneLabel;//手机号
@property(nonatomic, strong) UILabel *addressLabel; //地址


@property(nonatomic, strong) UIView *lineView; //线

@end
@implementation XJOrderDetailHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

#pragma mark - 一初始化
- (void)setupView{
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.aboveBgView];
    [self.aboveBgView addSubview:self.statusIconIv];
    [self.aboveBgView addSubview:self.matterLabe];
    [self.aboveBgView addSubview:self.expireLabel];
    
    
    [self.bgView addSubview:self.belowBgView];
    [self.belowBgView addSubview:self.locationIcon];
    [self.belowBgView addSubview:self.nameLabel];
    [self.belowBgView addSubview:self.phoneLabel];
    [self.belowBgView addSubview:self.addressLabel];
    [self.belowBgView addSubview:self.lineView];
}

#pragma mark - 一 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
    }
    return _bgView;
}





- (UIView *)aboveBgView {
    if (!_aboveBgView) {
        _aboveBgView = [[UIView alloc] init];
        _aboveBgView.backgroundColor = XJCOLOR_RGB(230, 230, 230);
        _aboveBgView.layer.masksToBounds = YES;
        _aboveBgView.layer.cornerRadius = 5;
    }
    return _aboveBgView;
}
- (UIImageView *)statusIconIv {
    if (!_statusIconIv) {
        _statusIconIv = [[UIImageView alloc] init];
        _statusIconIv.image = [UIImage imageNamed:@"Orderdet_fukuan"];
    }
    return _statusIconIv;
}
- (UILabel *)matterLabe {
    if (!_matterLabe) {
        _matterLabe = [[UILabel alloc] init];
    }
    return _matterLabe;
}

- (UILabel *)expireLabel {
    if (!_expireLabel) {
        _expireLabel = [[UILabel alloc] init];
    }
    return _expireLabel;
}





- (UIView *)belowBgView {
    if (!_belowBgView) {
        _belowBgView = [[UIView alloc] init];
    }
    return _belowBgView;
}

- (UIImageView *)locationIcon {
    if (!_locationIcon) {
        _locationIcon = [[UIImageView alloc] init];
        _locationIcon.image = [UIImage imageNamed:@"address_list_on"];
    }
    return _locationIcon;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc] init];
        _phoneLabel.font = [UIFont systemFontOfSize:13.0];
    }
    return _phoneLabel;
}
- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.font = [UIFont systemFontOfSize:14.0];
        _addressLabel.textColor = XJCOLOR_RGB(110, 110, 110);
        _addressLabel.numberOfLines = 0;
    }
    return _addressLabel;
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = XJCOLOR_RGB(110, 110, 110);
    }
    return _lineView;
}

#pragma mark - 二 layout
- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat kMargin = 15; // 间距
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // 上半部：h = 100
    [self.aboveBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(kMargin);
        make.right.equalTo(self.bgView.mas_right).offset(-kMargin);
        make.top.equalTo(self.bgView.mas_top).offset(kMargin);
        make.height.mas_equalTo(80);
    }];
    [self.statusIconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.aboveBgView.mas_centerY);
        make.left.equalTo(self.aboveBgView.mas_left).offset(30);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    // 等待买家付款、等待买家收货、等待快递员送货。。。。。
    [self.matterLabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.statusIconIv.mas_centerY);
        make.left.equalTo(self.statusIconIv.mas_right).offset(kMargin*2);
        make.right.equalTo(self.aboveBgView.mas_right).offset(-kMargin);
        make.height.mas_equalTo(20);
    }];
    // 2天23小时过期:有的有有的没有暂时不布局了。
    
    
    
    // 下半部：h: 80 : (上间距10 + 姓名 30 + 地址:不定 + 下间距10线条)
    [self.belowBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.aboveBgView.mas_bottom).offset(kMargin);
        make.left.right.bottom.equalTo(self.bgView);
    }];
    
    [self.locationIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        // 定位icon
        make.left.equalTo(self.belowBgView).offset(kMargin);
        make.size.mas_equalTo(CGSizeMake(10, 15));
        make.centerY.equalTo(self.belowBgView.mas_centerY);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        // 姓名
        make.top.equalTo(self.belowBgView.mas_top);
        make.left.equalTo(self.belowBgView.mas_left).offset(40);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       //手机号
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(120, 20));
    }];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        //地址
        make.left.equalTo(self.nameLabel.mas_left);
        make.right.equalTo(self.belowBgView.mas_right).offset(-kMargin);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
        make.bottom.equalTo(self.belowBgView.mas_bottom);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
       //线条
        make.left.equalTo(self.belowBgView.mas_left).offset(kMargin);
        make.right.equalTo(self.belowBgView.mas_right).offset(-kMargin);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.mas_bottom).offset(-1);
    }];
}


#pragma mark - 配置

- (void)configureOrderDetailHeaderViewWithMatter:(NSString *)matter name:(NSString *)name phone:(NSString *)phone addres:(NSString *)address{

    self.matterLabe.text = matter;
    self.nameLabel.text = name;
    self.phoneLabel.text = phone;
    self.addressLabel.text = address;
}


#pragma mark - 三 事件回调


@end
